package cn.chat.udp.ui.protocol;

public class ChatProtocol {
	//1#currentTimeMillis#userInfo#ip#1:Msg
	private String version;
	private int type;
	private String currentTimeMillis;
	private String userInfo;
	private String localIp;
	private String routeIp;
	private String msg;
	private int flag;
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getCurrentTimeMillis() {
		
		///return System.currentTimeMillis()+"";
		return System.currentTimeMillis()+"";
	}
	public String getUserInfo() {
		return userInfo;
	}

	public void setCurrentTimeMillis(String currentTimeMillis) {
		this.currentTimeMillis = currentTimeMillis;
	}

	public void setUserInfo(String userInfo) {
		this.userInfo = userInfo;
	}



	public String getLocalIp() {
		return localIp;
	}

	public void setLocalIp(String localIp) {
		this.localIp = localIp;
	}

	public String getRouteIp() {
		return routeIp;
	}

	public void setRouteIp(String routeIp) {
		this.routeIp = routeIp;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public String getString(String msg){
	//1#currentTimeMillis#userInfo#ip#:128:Msg
		return getVersion()+"#"+getCurrentTimeMillis()+"#"+getUserInfo()+"#"+getLocalIp()+"#"+type+"#:"+msg;
		
	}
	public String getString(){
		//1#currentTimeMillis#userInfo#ip#:128:Msg
			return getVersion()+"#"+getCurrentTimeMillis()+"#"+getUserInfo()+"#"+getLocalIp()+"#"+type+"#:"+getMsg();
			
		}
	public ChatProtocol getChatProtocol(String returnMsg){
		String[] split = returnMsg.split("#");
		String msg="";
		this.setVersion(split[0]);
		this.setCurrentTimeMillis(split[1]);
		this.setUserInfo(split[2]);
		this.setLocalIp(split[3]);
		this.setType(Integer.parseInt(split[4]));
		if(split.length>6){
			for (int i =5; i < split.length; i++) {
				
				msg+=split[i];
			}
		}else{
			msg=split[5];
		}
		
		this.setMsg(msg);
		return this;
		
	}
}
